package com.wptk.filemanager.ad

import android.app.Activity
import android.util.Log
import android.view.ViewGroup
import com.wptk.filemanager.BuildConfig
import com.wptk.filemanager.R
import com.hz.sdka.ada.*
import com.hz.sdka.commona.bean.HZAdError

/**
 * @Description:
 * @Author: lp
 * @CreateDate: 2021/09/29
 */
object AdLoadManager {

    /*加载信息流*/
    fun loadNative() {
        NativeAda.getInstance().setAdListener(object :
            AdListenera {
            override fun adLoading() {
                log("native adloading")
            }

            override fun adLoaded() {
                log("native adLoaded")
            }

            override fun adError(adError: HZAdError?) {
                log("native adError " + adError?.errorMsg)
            }
        })
        NativeAda.getInstance().load(BuildConfig.TOP_ON_CUSTOM_NATIVE_TD)
    }

    /*加载开屏*/
    fun loadSplash() {
        //可用于全局埋点
        Splasha.getInstance().setAdListener(object : AdListenera {
            override fun adLoading() {
                log("Splasha adloading")
            }

            override fun adLoaded() {
                log("Splasha adLoaded")
            }

            override fun adError(adError: HZAdError?) {
                log("Splasha adError " + adError?.errorMsg)
            }
        })
        Splasha.getInstance().load(BuildConfig.TOP_ON_SPLASH)
    }

    /*加载插屏*/
    fun loadInterstitial() {
        //可用于全局埋点
        Interstitiala.getInstance().setAdListener(object :
            AdListenera {
            override fun adLoading() {
                log("Interstitiala adLoading")
            }

            override fun adLoaded() {
                log("Interstitiala adLoaded")
            }

            override fun adError(adError: HZAdError?) {
                log("Interstitiala adError" + adError?.errorMsg)
            }
        })
        Interstitiala.getInstance().load(BuildConfig.TOP_ON_INTERSTITIAL)
    }

    /*加载激励视频*/
    fun loadRewardedVideo() {
        //可用于全局埋点
        RewardedVideoa.getInstance().setAdListener(object :
            AdListenera {
            override fun adLoading() {
                log("Rewarded adLoading")
            }

            override fun adLoaded() {
                log("Rewarded adLoaded")
            }

            override fun adError(adError: HZAdError?) {
                log("Rewarded adError" + adError?.errorMsg)
            }
        })
        RewardedVideoa.getInstance().load(BuildConfig.TOP_ON_REWARDED_VIDEO)
    }

    /*页面底部（TAB内）信息流，只有一个广告*/
    fun showInfoFlowEnd(viewGroup: ViewGroup?, scenarioId: String, adListener: AdListenera?) {
        //可用于全局埋点
        NativeAda.getInstance().setAdListener(object :
            AdListenera {
            override fun adLoading() {
                log("Native adLoading")
                adListener?.adLoading()
            }

            override fun adLoaded() {
                log("Native adLoaded")
                adListener?.adLoaded()
            }

            override fun adShow() {
                log("Native adShow")
                adListener?.adShow()
            }

            override fun adClose() {
                log("Native adClose")
                adListener?.adClose()
            }

            override fun adComplete() {
                log("Native adComplete")
                adListener?.adComplete()
            }

            override fun adError(adError: HZAdError?) {
                log("Native adError " + adError?.errorMsg)
                adListener?.adError(adError)
            }

            override fun adRequest() {
                log("Native adRequest")
                adListener?.adRequest()
            }

            override fun adReady() {
                log("Native adReady")
                adListener?.adReady()
            }

        })
        NativeAda.getInstance().showAd(viewGroup, BuildConfig.TOP_ON_CUSTOM_NATIVE_TD, scenarioId)
    }

    /*页面底部（TAB内）信息流，只有一个广告*/
    fun showNative(viewGroup: ViewGroup?, scenarioId: String, adListener: AdListenera?) {
        //可用于全局埋点
        NativeAda.getInstance().setAdListener(object :
            AdListenera {
            override fun adLoading() {
                log("Native adLoading")
                adListener?.adLoading()
            }

            override fun adLoaded() {
                log("Native adLoaded")
                adListener?.adLoaded()
            }

            override fun adShow() {
                log("Native adShow")
                adListener?.adShow()
            }

            override fun adClose() {
                log("Native adClose")
                adListener?.adClose()
            }

            override fun adComplete() {
                log("Native adComplete")
                adListener?.adComplete()
            }

            override fun adError(adError: HZAdError?) {
                log("Native adError " + adError?.errorMsg)
                adListener?.adError(adError)
            }

            override fun adRequest() {
                log("Native adRequest")
                adListener?.adRequest()
            }

            override fun adReady() {
                log("Native adReady")
                adListener?.adReady()
            }

        })
        NativeAda.getInstance().showAd(viewGroup, BuildConfig.TOP_ON_CUSTOM_NATIVE_TD, scenarioId, R.layout.native_ad_layout_fba)
    }


    /*显示开屏广告*/
    fun showSplashAd(activity: Activity, viewGroup: ViewGroup, scenarioId: String, adListener: AdListenera?) {
        //可用于全局埋点
        Splasha.getInstance().setAdListener(object : AdListenera {
            override fun adLoading() {
                log("Splasha adLoading")
                adListener?.adLoading()
            }

            override fun adLoaded() {
                log("Splasha adLoaded")
                adListener?.adLoaded()
            }

            override fun adShow() {
                log("Splasha adShow")
                adListener?.adShow()
            }

            override fun adClose() {
                log("Splasha adClose")
                adListener?.adClose()
            }

            override fun adComplete() {
                log("Splasha adComplete")
                adListener?.adComplete()
            }

            override fun adError(adError: HZAdError?) {
                log("Splasha adError " + adError?.errorMsg)
                adListener?.adError(adError)
            }

            override fun adRequest() {
                log("Splasha adRequest")
                adListener?.adRequest()
            }

            override fun adReady() {
                log("Splasha adReady")
                adListener?.adReady()
            }


        })
        Splasha.getInstance().showAd(activity, viewGroup, BuildConfig.TOP_ON_INTERSTITIAL, scenarioId)
    }

    /*插页式广告*/
    fun showInterstitialAd(activity: Activity, scenarioId: String, adListener: AdListenera?) {
        //可用于全局埋点
        Interstitiala.getInstance().setAdListener(object :
            AdListenera {
            override fun adLoading() {
                log("Interstitiala adLoading")
                adListener?.adLoading()
            }

            override fun adLoaded() {
                log("Interstitiala adLoaded")
                adListener?.adLoaded()
            }

            override fun adShow() {
                log("Interstitiala adShow")
                adListener?.adShow()
            }

            override fun adClose() {
                log("Interstitiala adClose")
                adListener?.adClose()
            }

            override fun adComplete() {
                log("Interstitiala adComplete")
                adListener?.adComplete()
            }

            override fun adError(adError: HZAdError?) {
                log("Interstitiala adError " + adError?.errorMsg)
                adListener?.adError(adError)
            }

            override fun adRequest() {
                log("Interstitiala adRequest")
                adListener?.adRequest()
            }

            override fun adReady() {
                log("Interstitiala adReady")
                adListener?.adReady()
            }


        })
        Interstitiala.getInstance().showAd(activity, BuildConfig.TOP_ON_INTERSTITIAL, scenarioId)
    }

    /*激励视频*/
    fun showRewardedVideoAd(activity: Activity, scenarioId: String, adListener: AdListenera?) {
        //可用于全局埋点
        RewardedVideoa.getInstance().setAdListener(object :
            AdListenera {
            override fun adLoading() {
                log("Rewarded adLoading")
                adListener?.adLoading()
            }

            override fun adLoaded() {
                log("Rewarded adLoaded")
                adListener?.adLoaded()
            }

            override fun adShow() {
                log("Rewarded adShow")
                adListener?.adShow()
            }

            override fun adClose() {
                log("Rewarded adClose")
                adListener?.adClose()
            }

            override fun adComplete() {
                log("Rewarded adComplete")
                adListener?.adComplete()
            }

            override fun adError(adError: HZAdError?) {
                log("Rewarded adError " + adError?.errorMsg)
                adListener?.adError(adError)
            }

            override fun adRequest() {
                log("Rewarded adRequest")
                adListener?.adRequest()
            }

            override fun adReady() {
                log("Rewarded adReady")
                adListener?.adReady()
            }


        })
        RewardedVideoa.getInstance().showAd(activity, BuildConfig.TOP_ON_REWARDED_VIDEO, scenarioId)
    }

    private fun log(str: String) {
        Log.d("AdLoadManager", str)
    }

}